package com.kanshu.ksgb.fastread.doudou.app.test

import android.os.Bundle
import android.os.PersistableBundle
import android.view.WindowManager
import android.os.Build
import android.app.Activity
import android.support.v7.app.AppCompatActivity
import android.support.v7.app.AppCompatDelegate
import android.view.View







open class BaseActivity : AppCompatActivity() {
    companion object {
        var isNightMode = false
        var count = 0
    }

    var currentIsNightMode = false

    override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
        super.onCreate(savedInstanceState, persistentState)
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
        hideStableStatusBar(this)
        currentIsNightMode = isNightMode
    }

    override fun onResume() {
        super.onResume()
        if (currentIsNightMode != isNightMode) {
            currentIsNightMode = isNightMode
            if (isNightMode) {
                delegate.setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES)
            } else {
                delegate.setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO)
            }
        }
    }

    fun transparentStatusBar(activity: Activity) {
        if (Build.VERSION.SDK_INT >= 21) {
//            expandStatusBar(activity)
            activity.window.statusBarColor = activity.resources.getColor(android.R.color.transparent)
        } else if (Build.VERSION.SDK_INT >= 19) {
            val attrs = activity.window.attributes
            attrs.flags = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS or attrs.flags
            activity.window.attributes = attrs
        }
    }

    private val STABLE_STATUS = View.SYSTEM_UI_FLAG_FULLSCREEN or
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
    fun hideStableStatusBar(activity: Activity) {
        //App全屏，隐藏StatusBar
        setFlag(activity, STABLE_STATUS)
    }

    fun setFlag(activity: Activity, flag: Int) {
        if (Build.VERSION.SDK_INT >= 19) {
            val decorView = activity.window.decorView
            val option = decorView.systemUiVisibility or flag
            decorView.systemUiVisibility = option
        }
    }
}